package engine.graphics;

import java.awt.Color;
import java.awt.Font;
import java.util.HashMap;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.font.effects.ColorEffect;

import engine.MADGL;

@SuppressWarnings("unchecked")
public final class FontManager {

	private static UnicodeFont FONT_24, FONT_20, 
							  FONT_16, FONT_13,
							  FONT_11,FONT_11_ ,  
							  FONT_9, FONT_9_ , 
							  FONT_24_black, FONT_20_black,
							  FONT_16_black, FONT_13_black,
							  FONT_11_black, FONT_9_black,
							  FONT_11_black_ ; 
	
	private static final String FONT_FAMILY = "Lucida Console" ; 
	
	public static final String S_FONT_24 = "Font24",
							   S_FONT_20 = "Font20",
							   S_FONT_16 = "Font16",
							   S_FONT_13 = "Font13",
							   S_FONT_11 = "Font11",
							   S_FONT_11_ = "Font11_NBold", 
							   S_FONT_9 = "Font9",
							   S_FONT_9_ = "Font9_NBold", 
							   S_FONT_24_black = "Font24Black",
							   S_FONT_20_black = "Font20Black",
							   S_FONT_16_black = "Font16Black",
							   S_FONT_13_black = "Font13Black",
							   S_FONT_11_black = "Font11Black",
							   S_FONT_11_black_ = "Font11Black_NBold",
							   S_FONT_9_black = "Font9Black" ;

	public static final char COPY_SIGN = 169; 
								
	
	private static HashMap<String, UnicodeFont> fonts ;  
	
	static{
		FONT_24 = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 24));  
		FONT_24.getEffects().add(new ColorEffect(Color.white));
		FONT_24.addAsciiGlyphs();

		FONT_20 = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 20));  
		FONT_20.getEffects().add(new ColorEffect(Color.white));
		FONT_20.addAsciiGlyphs();

		FONT_16 = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 16));  
		FONT_16.getEffects().add(new ColorEffect(Color.white));
		FONT_16.addAsciiGlyphs();

		FONT_13 = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 13));  
		FONT_13.getEffects().add(new ColorEffect(Color.white));
		FONT_13.addAsciiGlyphs();
		
		FONT_11 = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 11));  
		FONT_11.getEffects().add(new ColorEffect(Color.white));
		FONT_11.addAsciiGlyphs();

		FONT_11_ = new UnicodeFont(new Font(FONT_FAMILY, Font.PLAIN, 11));  
		FONT_11_.getEffects().add(new ColorEffect(Color.white));
		FONT_11_.addAsciiGlyphs();
		
		FONT_9 = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 9));  
		FONT_9.getEffects().add(new ColorEffect(Color.white));
		FONT_9.addAsciiGlyphs();

		FONT_9_ = new UnicodeFont(new Font(FONT_FAMILY, Font.PLAIN, 9));  
		FONT_9_.getEffects().add(new ColorEffect(Color.white));
		FONT_9_.addAsciiGlyphs();

		FONT_24_black = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 24));  
		FONT_24_black.getEffects().add(new ColorEffect(Color.black));
		FONT_24_black.addAsciiGlyphs();
		
		FONT_20_black = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 20));  
		FONT_20_black.getEffects().add(new ColorEffect(Color.black));
		FONT_20_black.addAsciiGlyphs();
		
		FONT_16_black = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 16));  
		FONT_16_black.getEffects().add(new ColorEffect(Color.black));
		FONT_16_black.addAsciiGlyphs();
		
		FONT_13_black = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 13));  
		FONT_13_black.getEffects().add(new ColorEffect(Color.black));
		FONT_13_black.addAsciiGlyphs();

		FONT_11_black = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 11));  
		FONT_11_black.getEffects().add(new ColorEffect(Color.black));
		FONT_11_black.addAsciiGlyphs();

		FONT_11_black_ = new UnicodeFont(new Font(FONT_FAMILY, Font.PLAIN, 11)); 
		FONT_11_black_.getEffects().add(new ColorEffect(Color.black)); 
		FONT_11_black_.addAsciiGlyphs(); 
		
		FONT_9_black = new UnicodeFont(new Font(FONT_FAMILY, Font.BOLD, 9));  
		FONT_9_black.getEffects().add(new ColorEffect(Color.black));
		FONT_9_black.addAsciiGlyphs();
		
		try {
			FONT_24.loadGlyphs();
			FONT_20.loadGlyphs();
			FONT_16.loadGlyphs();
			FONT_13.loadGlyphs();
			FONT_11.loadGlyphs();
			FONT_11_.loadGlyphs();
			FONT_9.loadGlyphs();
			FONT_9_.loadGlyphs();
			FONT_24_black.loadGlyphs(); 
			FONT_20_black.loadGlyphs(); 
			FONT_16_black.loadGlyphs(); 
			FONT_13_black.loadGlyphs(); 
			FONT_11_black.loadGlyphs();
			FONT_11_black_.loadGlyphs(); 
			FONT_9_black.loadGlyphs(); 
		} catch (SlickException e) {
			e.printStackTrace();
		} 
		
		fonts = new HashMap<String, UnicodeFont>(); 
		fonts.put(S_FONT_24, FONT_24);
		fonts.put(S_FONT_20, FONT_20);
		fonts.put(S_FONT_16, FONT_16); 
		fonts.put(S_FONT_13, FONT_13);
		fonts.put(S_FONT_11, FONT_11);
		fonts.put(S_FONT_11_, FONT_11_);
		fonts.put(S_FONT_9, FONT_9);
		fonts.put(S_FONT_9_, FONT_9_);
		fonts.put(S_FONT_24_black, FONT_24_black);
		fonts.put(S_FONT_20_black, FONT_20_black);
		fonts.put(S_FONT_16_black, FONT_16_black);
		fonts.put(S_FONT_13_black, FONT_13_black);
		fonts.put(S_FONT_11_black, FONT_11_black);
		fonts.put(S_FONT_11_black_, FONT_11_black_);
		fonts.put(S_FONT_9_black, FONT_9_black);
		
	}

	public static UnicodeFont getFontByName(String fontName) {
		return fonts.get(fontName);
	}
	
	public static void drawString(String fontName, int x, int y, String text){
		MADGL.switchToUpsideDownOrthoView();
		getFontByName(fontName).drawString(x, y, text); 
		MADGL.switchToDefaultOrthoView();
		
	}
	
}
